<!DOCTYPE html>
<html id="docs" lang="en" class="">
	<head>
	<meta charset="utf-8">
<title>Deployments - Kubernetes</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/png" href="../../../../../images/favicon.png">
<link rel="stylesheet" type="text/css" href="../../../../../css/base_fonts.css">
<link rel="stylesheet" type="text/css" href="../../../../../css/styles.css">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
<link rel="stylesheet" type="text/css" href="../../../../../css/callouts.css">
<link rel="stylesheet" type="text/css" href="../../../../../css/custom-jekyll/tags.css">




<meta name="description" content="Deployments" />
<meta property="og:description" content="Deployments" />

<meta property="og:url" content="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" />
<meta property="og:title" content="Deployments - Kubernetes" />

<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<script src="../../../../../js/script.js"></script>
<script src="../../../../../js/custom-jekyll/tags.js"></script>


	</head>
	<body>
		<div id="cellophane" onclick="kub.toggleMenu()"></div>

<header>
    <a href="../../../../../index.html" class="logo"></a>

    <div class="nav-buttons" data-auto-burger="primary">
        <ul class="global-nav">
            
            
            <li><a href="../../../../home.1">Documentation</a></li>
            
            <li><a href="../../../../../blog/index.html">Blog</a></li>
            
            <li><a href="../../../../../partners/index.html">Partners</a></li>
            
            <li><a href="../../../../../community/index.html">Community</a></li>
            
            <li><a href="../../../../../case-studies/index.html">Case Studies</a></li>
            
            
             <li>
                <a href="index.html#">
                    English <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="../../../../../zh/index.html">中文 Chinese</a></li>
                
                    <li><a href="../../../../../ko/index.html">한국어 Korean</a></li>
                
                </ul>
            </li>
         
            <li>
                <a href="index.html#">
                    v1.11 <span class="ui-icon ui-icon-carat-1-s"></span>
                </a>
                <ul>
                
                    <li><a href="https://kubernetes.io">v1.12</a></li>
                
                    <li><a href="../../../../../index.html">v1.11</a></li>
                
                    <li><a href="https://v1-10.docs.kubernetes.io">v1.10</a></li>
                
                    <li><a href="https://v1-9.docs.kubernetes.io">v1.9</a></li>
                
                </ul>
            </li>
        </ul>
        
        <a href="../../../../tutorials/kubernetes-basics/index.html" class="button" id="tryKubernetes" data-auto-burger-exclude>Try Kubernetes</a>
        <button id="hamburger" onclick="kub.toggleMenu()" data-auto-burger-exclude><div></div></button>
    </div>

    <nav id="mainNav">
        <main data-auto-burger="primary">
        <div class="nav-box">
            <h3><a href="../../../../tutorials/stateless-application/hello-minikube/index.html">Get Started</a></h3>
            <p>Ready to get your hands dirty? Build a simple Kubernetes cluster that runs "Hello World" for Node.js.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../../home.1">Documentation</a></h3>
            <p>Learn how to use Kubernetes with the use of walkthroughs, samples, and reference documentation. You can even <a href="../../../../../editdocs/index.html" data-auto-burger-exclude>help contribute to the docs</a>!</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../../../community/index.html">Community</a></h3>
            <p>If you need help, you can connect with other Kubernetes users and the Kubernetes authors, attend community events, and watch video presentations from around the web.</p>
        </div>
        <div class="nav-box">
            <h3><a href="../../../../../blog/index.html">Blog</a></h3>
            <p>Read the latest news for Kubernetes and the containers space in general, and get technical how-tos hot off the presses.</p>
        </div>
        </main>
        <main data-auto-burger="primary">
        <div class="left">
            <h5 class="github-invite">Interested in hacking on the core Kubernetes code base?</h5>
            <a href="https://github.com/kubernetes/kubernetes" class="button" data-auto-burger-exclude>View On Github</a>
        </div>

        <div class="right">
            <h5 class="github-invite">Explore the community</h5>
            <div class="social">
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>Twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
        </div>
        <div class="clear" style="clear: both"></div>
        </main>
    </nav>
</header>

		
		
		<section id="hero" class="light-text no-sub">
			









<h1>Concepts</h1>
<h5></h5>








<div id="vendorStrip" class="light-text">
	<ul>
		
		
		<li><a href="../../../../home.1">DOCUMENTATION</a></li>
		
		
		<li><a href="../../../../setup/index.html">SETUP</a></li>
		
		
		<li><a href="../../../index.html" class="YAH">CONCEPTS</a></li>
		
		
		<li><a href="../../../../tasks/index.html">TASKS</a></li>
		
		
		<li><a href="../../../../tutorials/index.html">TUTORIALS</a></li>
		
		
		<li><a href="../../../../reference.1">REFERENCE</a></li>
		
	</ul>
	<div id="searchBox">
		<input type="text" id="search" placeholder="Search" onkeydown="if (event.keyCode==13) window.location.replace('/docs/search/?q=' + this.value)" autofocus="autofocus">
	</div>
</div>

		</section>
		
		
<section id="deprecationWarning">
  <main>
    <div class="content deprecation-warning">
      <h3>
        Documentation for Kubernetes v1.11 is no longer actively maintained. The version you are currently viewing is a static snapshot.
        For up-to-date documentation, see the <a href="https://kubernetes.io/docs/home/">latest</a> version.
      </h3>
    </div>
  </main>
</section>


		<section id="encyclopedia">
			
<div id="docsToc">
     <div class="pi-accordion">
    	
        
        
        
        
        
         
             
                 
             
         
             
                 
             
         
             
                 
                          
                          
                 
             
         
             
         
             
         
             
         
             
         
             
         
         
        
        <a class="item" data-title="Concepts" href="../../../index.html"></a>

	
	
		
		
	<div class="item" data-title="Overview">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="What is Kubernetes?" href="../../../overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Kubernetes Components" href="../../../overview/components.1"></a>

		
	
		
		
<a class="item" data-title="The Kubernetes API" href="../../../overview/kubernetes-api/index.html"></a>

		
	
		
		
	<div class="item" data-title="Working with Kubernetes Objects">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Understanding Kubernetes Objects" href="../../../overview/working-with-objects/kubernetes-objects.1"></a>

		
	
		
		
<a class="item" data-title="Names" href="../../../../user-guide/identifiers"></a>

		
	
		
		
<a class="item" data-title="Namespaces" href="../../../overview/working-with-objects/namespaces.1"></a>

		
	
		
		
<a class="item" data-title="Labels and Selectors" href="../../../../user-guide/labels"></a>

		
	
		
		
<a class="item" data-title="Annotations" href="../../../overview/working-with-objects/annotations.1"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Object Management Using kubectl">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Kubernetes Object Management" href="../../../../tutorials/object-management-kubectl/object-management/index.html"></a>

		
	
		
		
<a class="item" data-title="Managing Kubernetes Objects Using Imperative Commands" href="../../../../tutorials/object-management-kubectl/imperative-object-management-command/index.html"></a>

		
	
		
		
<a class="item" data-title="Imperative Management of Kubernetes Objects Using Configuration Files" href="../../../../tutorials/object-management-kubectl/imperative-object-management-configuration/index.html"></a>

		
	
		
		
<a class="item" data-title="Declarative Management of Kubernetes Objects Using Configuration Files" href="../../../../tutorials/object-management-kubectl/declarative-object-management-configuration/index.html"></a>

		
	

		</div>
	</div>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Compute, Storage, and Networking Extensions">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Cluster Administration Overview" href="../../../cluster-administration/cluster-administration-overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Certificates" href="../../../cluster-administration/certificates/index.html"></a>

		
	
		
		
<a class="item" data-title="Cloud Providers" href="../../../cluster-administration/cloud-providers/index.html"></a>

		
	
		
		
<a class="item" data-title="Managing Resources" href="../../../cluster-administration/manage-deployment/index.html"></a>

		
	
		
		
<a class="item" data-title="Cluster Networking" href="../../../../admin/networking"></a>

		
	
		
		
<a class="item" data-title="Logging Architecture" href="../../../cluster-administration/logging.1"></a>

		
	
		
		
<a class="item" data-title="Configuring kubelet Garbage Collection" href="../../../cluster-administration/kubelet-garbage-collection/index.html"></a>

		
	
		
		
<a class="item" data-title="Federation" href="../../../cluster-administration/federation/index.html"></a>

		
	
		
		
<a class="item" data-title="Proxies in Kubernetes" href="../../../cluster-administration/proxies/index.html"></a>

		
	
		
		
<a class="item" data-title="Controller manager metrics" href="../../../cluster-administration/controller-metrics/index.html"></a>

		
	
		
		
<a class="item" data-title="Installing Addons" href="../../../cluster-administration/addons/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Kubernetes Architecture">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Nodes" href="../../../../admin/node.1"></a>

		
	
		
		
<a class="item" data-title="Master-Node communication" href="../../../architecture/master-node-communication/index.html"></a>

		
	
		
		
<a class="item" data-title="Concepts Underlying the Cloud Controller Manager" href="../../../architecture/cloud-controller/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Extending Kubernetes">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Extending your Kubernetes Cluster" href="../../../overview/extending/index.html"></a>

		
	
		
		
	<div class="item" data-title="Extending the Kubernetes API">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Extending the Kubernetes API with the aggregation layer" href="../../../api-extension/apiserver-aggregation.1"></a>

		
	
		
		
<a class="item" data-title="Custom Resources" href="../../../api-extension/custom-resources/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Compute, Storage, and Networking Extensions">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Network Plugins" href="../../../../admin/network-plugins/index.html"></a>

		
	
		
		
<a class="item" data-title="Device Plugins" href="../../../cluster-administration/device-plugins.1"></a>

		
	

		</div>
	</div>

		
	
		
		
<a class="item" data-title="Service Catalog" href="../../../service-catalog/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Containers">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Images" href="../../../containers/images/index.html"></a>

		
	
		
		
<a class="item" data-title="Container Environment Variables" href="../../../containers/container-environment-variables/index.html"></a>

		
	
		
		
<a class="item" data-title="Container Lifecycle Hooks" href="../../../containers/container-lifecycle-hooks/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Workloads">
		<div class="container">
		
		
	
	
		
		
	<div class="item" data-title="Pods">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Pod Overview" href="../../pods/pod-overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Pods" href="../../../../user-guide/pods/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Lifecycle" href="../../../../user-guide/pod-states/index.html"></a>

		
	
		
		
<a class="item" data-title="Init Containers" href="../../../abstractions/init-containers/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Preset" href="../../pods/podpreset/index.html"></a>

		
	
		
		
<a class="item" data-title="Disruptions" href="../../pods/disruptions/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Controllers">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="ReplicaSet" href="../replicaset/index.html"></a>

		
	
		
		
<a class="item" data-title="ReplicationController" href="../../../../user-guide/replication-controller/index.html"></a>

		
	
		
		
<a class="item" data-title="Deployments" href="index.html"></a>

		
	
		
		
<a class="item" data-title="StatefulSets" href="../statefulset.md"></a>

		
	
		
		
<a class="item" data-title="DaemonSet" href="../daemonset.1"></a>

		
	
		
		
<a class="item" data-title="Garbage Collection" href="../garbage-collection/index.html"></a>

		
	
		
		
<a class="item" data-title="Jobs - Run to Completion" href="../jobs-run-to-completion.1"></a>

		
	
		
		
<a class="item" data-title="CronJob" href="../cron-jobs.1"></a>

		
	

		</div>
	</div>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Configuration">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Configuration Best Practices" href="../../../configuration/overview/index.html"></a>

		
	
		
		
<a class="item" data-title="Managing Compute Resources for Containers" href="../../../../user-guide/compute-resources/index.html"></a>

		
	
		
		
<a class="item" data-title="Assigning Pods to Nodes" href="../../../../user-guide/node-selection/index.html"></a>

		
	
		
		
<a class="item" data-title="Taints and Tolerations" href="../../../configuration/taint-and-toleration.1"></a>

		
	
		
		
<a class="item" data-title="Secrets" href="../../../../user-guide/secrets.1"></a>

		
	
		
		
<a class="item" data-title="Organizing Cluster Access Using kubeconfig Files" href="../../../configuration/organize-cluster-access-kubeconfig/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Priority and Preemption" href="../../../configuration/pod-priority-preemption/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Services, Load Balancing, and Networking">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Services" href="../../../../user-guide/services"></a>

		
	
		
		
<a class="item" data-title="DNS for Services and Pods" href="../../../services-networking/dns-pod-service/index.html"></a>

		
	
		
		
<a class="item" data-title="Connecting Applications with Services" href="../../../services-networking/connect-applications-service.1"></a>

		
	
		
		
<a class="item" data-title="Ingress" href="../../../services-networking/ingress/index.html"></a>

		
	
		
		
<a class="item" data-title="Network Policies" href="../../../services-networking/networkpolicies/index.html"></a>

		
	
		
		
<a class="item" data-title="Adding entries to Pod /etc/hosts with HostAliases" href="../../../services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Storage">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Volumes" href="../../../storage/volumes.1"></a>

		
	
		
		
<a class="item" data-title="Persistent Volumes" href="../../../../user-guide/persistent-volumes/index.html"></a>

		
	
		
		
<a class="item" data-title="Storage Classes" href="../../../storage/storage-classes.1"></a>

		
	
		
		
<a class="item" data-title="Dynamic Volume Provisioning" href="../../../storage/dynamic-provisioning/index.html"></a>

		
	
		
		
<a class="item" data-title="Node-specific Volume Limits" href="../../../storage/storage-limits/index.html"></a>

		
	

		</div>
	</div>

		
	
		
		
	<div class="item" data-title="Policies">
		<div class="container">
		
		
	
	
		
		
<a class="item" data-title="Resource Quotas" href="../../../policy/resource-quotas/index.html"></a>

		
	
		
		
<a class="item" data-title="Pod Security Policies" href="../../../../user-guide/pod-security-policy"></a>

		
	

		</div>
	</div>

		
	






     </div> 
    <button class="push-menu-close-button" onclick="kub.toggleToc()"></button>
</div> 

			<div id="docsContent">
				
<p><a href="../../../../editdocs#docs/concepts/workloads/controllers/deployment.md" id="editPageButton">Edit This Page</a></p>

<h1>Deployments</h1>



<p>A <em>Deployment</em> controller provides declarative updates for <a href="../../../../user-guide/pods/index.html">Pods</a> and
<a href="../replicaset/index.html">ReplicaSets</a>.</p>

<p>You describe a <em>desired state</em> in a Deployment object, and the Deployment controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.</p>

<blockquote class="note">
  <div><strong>Note:</strong> You should not manage ReplicaSets owned by a Deployment. All the use cases should be covered by manipulating the Deployment object. Consider opening an issue in the main Kubernetes repository if your use case is not covered below.</div>
</blockquote>









<ul id="markdown-toc">










<li><a href="index.html#use-case">Use Case</a></li>




<li><a href="index.html#creating-a-deployment">Creating a Deployment</a></li>




<li><a href="index.html#updating-a-deployment">Updating a Deployment</a></li>




<li><a href="index.html#rolling-back-a-deployment">Rolling Back a Deployment</a></li>




<li><a href="index.html#scaling-a-deployment">Scaling a Deployment</a></li>




<li><a href="index.html#pausing-and-resuming-a-deployment">Pausing and Resuming a Deployment</a></li>




<li><a href="index.html#deployment-status">Deployment status</a></li>




<li><a href="index.html#clean-up-policy">Clean up Policy</a></li>




<li><a href="index.html#use-cases">Use Cases</a></li>




<li><a href="index.html#writing-a-deployment-spec">Writing a Deployment Spec</a></li>




<li><a href="index.html#alternative-to-deployments">Alternative to Deployments</a></li>



















</ul>


<h2 id="use-case">Use Case</h2>

<p>The following are typical use cases for Deployments:</p>

<ul>
<li><a href="index.html#creating-a-deployment">Create a Deployment to rollout a ReplicaSet</a>. The ReplicaSet creates Pods in the background. Check the status of the rollout to see if it succeeds or not.</li>
<li><a href="index.html#updating-a-deployment">Declare the new state of the Pods</a> by updating the PodTemplateSpec of the Deployment. A new ReplicaSet is created and the Deployment manages moving the Pods from the old ReplicaSet to the new one at a controlled rate. Each new ReplicaSet updates the revision of the Deployment.</li>
<li><a href="index.html#rolling-back-a-deployment">Rollback to an earlier Deployment revision</a> if the current state of the Deployment is not stable. Each rollback updates the revision of the Deployment.</li>
<li><a href="index.html#scaling-a-deployment">Scale up the Deployment to facilitate more load</a>.</li>
<li><a href="index.html#pausing-and-resuming-a-deployment">Pause the Deployment</a> to apply multiple fixes to its PodTemplateSpec and then resume it to start a new rollout.</li>
<li><a href="index.html#deployment-status">Use the status of the Deployment</a> as an indicator that a rollout has stuck.</li>
<li><a href="index.html#clean-up-policy">Clean up older ReplicaSets</a> that you don&rsquo;t need anymore.</li>
</ul>

<h2 id="creating-a-deployment">Creating a Deployment</h2>

<p>The following is an example of a Deployment. It creates a ReplicaSet to bring up three <code>nginx</code> Pods:</p>

<table class="includecode" id="nginx-deployment-yaml">
    <thead>
        <tr>
            <th>
                <a href="https://github.com/kubernetes/website/blob/master/content/en/docs/concepts/workloads/controllers/nginx-deployment.yaml" download="nginx-deployment.yaml">
                    <code>nginx-deployment.yaml docs/concepts/workloads/controllers</code>
                </a>
                <img src="../../../../../images/copycode.svg" style="max-height:24px" onclick="copyCode('nginx-deployment-yaml')" title="Copy nginx-deployment.yaml to clipboard">
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml">apiVersion:<span style="color:#bbb"> </span>apps/v1<span style="color:#bbb">
</span><span style="color:#bbb"></span>kind:<span style="color:#bbb"> </span>Deployment<span style="color:#bbb">
</span><span style="color:#bbb"></span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>name:<span style="color:#bbb"> </span>nginx-deployment<span style="color:#bbb">
</span><span style="color:#bbb">  </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb"></span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">  </span>replicas:<span style="color:#bbb"> </span><span style="color:#666">3</span><span style="color:#bbb">
</span><span style="color:#bbb">  </span>selector:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>matchLabels:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">  </span>template:<span style="color:#bbb">
</span><span style="color:#bbb">    </span>metadata:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>labels:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>app:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">    </span>spec:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>containers:<span style="color:#bbb">
</span><span style="color:#bbb">      </span>-<span style="color:#bbb"> </span>name:<span style="color:#bbb"> </span>nginx<span style="color:#bbb">
</span><span style="color:#bbb">        </span>image:<span style="color:#bbb"> </span>nginx:<span style="color:#666">1.7</span>.<span style="color:#666">9</span><span style="color:#bbb">
</span><span style="color:#bbb">        </span>ports:<span style="color:#bbb">
</span><span style="color:#bbb">        </span>-<span style="color:#bbb"> </span>containerPort:<span style="color:#bbb"> </span><span style="color:#666">80</span><span style="color:#bbb">
</span><span style="color:#bbb"></span></code></pre></div>  </td>
        </tr>
    </tbody>
</table>

<p>In this example:</p>

<ul>
<li>A Deployment named <code>nginx-deployment</code> is created, indicated by the <code>.metadata.name</code> field.</li>
<li>The Deployment creates three replicated Pods, indicated by the <code>replicas</code> field.</li>
<li>The <code>selector</code> field defines how the Deployment finds which Pods to manage.
In this case, we simply select on one label defined in the Pod template (<code>app: nginx</code>).
However, more sophisticated selection rules are possible,
as long as the Pod template itself satisfies the rule.</li>
<li>The Pod template&rsquo;s specification, or <code>.template.spec</code> field, indicates that
the Pods run one container, <code>nginx</code>, which runs the <code>nginx</code>
<a href="https://hub.docker.com/" target="_blank">Docker Hub</a> image at version 1.7.9.</li>
<li>The Deployment opens port 80 for use by the Pods.</li>
</ul>

<blockquote class="note">
  <div><strong>Note:</strong> <code>matchLabels</code> is a map of {key,value} pairs. A single {key,value} in the <code>matchLabels</code> map
is equivalent to an element of <code>matchExpressions</code>, whose key field is &ldquo;key&rdquo;, the operator is &ldquo;In&rdquo;,
and the values array contains only &ldquo;value&rdquo;. The requirements are ANDed.</div>
</blockquote>

<p>The <code>template</code> field contains the following instructions:</p>

<ul>
<li>The Pods are labeled <code>app: nginx</code></li>
<li>Create one container and name it <code>nginx</code>.</li>
<li>Run the <code>nginx</code> image at version <code>1.7.9</code>.</li>
<li>Open port <code>80</code> so that the container can send and accept traffic.</li>
</ul>

<p>To create this Deployment, run the following command:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create -f  https://raw.githubusercontent.com/kubernetes/website/master/content/en/docs/concepts/workloads/controllers/nginx-deployment.yaml</code></pre></div>
<blockquote class="note">
  <div><strong>Note:</strong> You can append <code>--record</code> to this command to record the current command in the annotations of
the created or updated resource. This is useful for future review, such as investigating which
commands were executed in each Deployment revision.</div>
</blockquote>

<p>Next, run <code>kubectl get deployments</code>. The output is similar to the following:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   <span style="color:#666">3</span>         <span style="color:#666">0</span>         <span style="color:#666">0</span>            <span style="color:#666">0</span>           1s</code></pre></div>
<p>When you inspect the Deployments in your cluster, the following fields are displayed:</p>

<ul>
<li><code>NAME</code> lists the names of the Deployments in the cluster.</li>
<li><code>DESIRED</code> displays the desired number of <em>replicas</em> of the application, which
you define when you create the Deployment. This is the <em>desired state</em>.</li>
<li><code>CURRENT</code> displays how many replicas are currently running.</li>
<li><code>UP-TO-DATE</code> displays the number of replicas that have been updated to achieve
the desired state.</li>
<li><code>AVAILABLE</code> displays how many replicas of the application are available to
your users.</li>
<li><code>AGE</code> displays the amount of time that the application has been running.</li>
</ul>

<p>Notice how the values in each field correspond to the values in the Deployment specification:</p>

<ul>
<li>The number of desired replicas is 3 according to <code>.spec.replicas</code> field.</li>
<li>The number of current replicas is 0 according to the <code>.status.replicas</code> field.</li>
<li>The number of up-to-date replicas is 0 according to the <code>.status.updatedReplicas</code> field.</li>
<li>The number of available replicas is 0 according to the <code>.status.availableReplicas</code> field.</li>
</ul>

<p>To see the Deployment rollout status, run <code>kubectl rollout status deployment/nginx-deployment</code>. This command returns the following output:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">Waiting <span style="color:#a2f;font-weight:bold">for</span> rollout to finish: <span style="color:#666">2</span> out of <span style="color:#666">3</span> new replicas have been updated...
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> successfully rolled out</code></pre></div>
<p>Run the <code>kubectl get deployments</code> again a few seconds later:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>            <span style="color:#666">3</span>           18s</code></pre></div>
<p>Notice that the Deployment has created all three replicas, and all replicas are up-to-date (they contain the
latest Pod template) and available (the Pod status is Ready for at least the value of the Deployment&rsquo;s <code>.spec.minReadySeconds</code> field).</p>

<p>To see the ReplicaSet (<code>rs</code>) created by the deployment, run <code>kubectl get rs</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-2035384211   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>       18s</code></pre></div>
<p>Notice that the name of the ReplicaSet is always formatted as <code>[DEPLOYMENT-NAME]-[POD-TEMPLATE-HASH-VALUE]</code>. The hash value is automatically generated when the Deployment is created.</p>

<p>To see the labels automatically generated for each pod, run <code>kubectl get pods --show-labels</code>. The following output is returned:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">NAME                                READY     STATUS    RESTARTS   AGE       LABELS
nginx-deployment-2035384211-7ci7o   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          18s       <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx,pod-template-hash<span style="color:#666">=</span><span style="color:#666">2035384211</span>
nginx-deployment-2035384211-kzszj   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          18s       <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx,pod-template-hash<span style="color:#666">=</span><span style="color:#666">2035384211</span>
nginx-deployment-2035384211-qqcnn   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          18s       <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx,pod-template-hash<span style="color:#666">=</span><span style="color:#666">2035384211</span></code></pre></div>
<p>The created ReplicaSet ensures that there are three <code>nginx</code> Pods running at all times.</p>

<blockquote class="note">
  <div><strong>Note:</strong> You must specify an appropriate selector and Pod template labels in a Deployment (in this case,
<code>app: nginx</code>). Do not overlap labels or selectors with other controllers (including other Deployments and StatefulSets). Kubernetes doesn&rsquo;t stop you from overlapping, and if multiple controllers have overlapping selectors those controllers might conflict and behave unexpectedly.</div>
</blockquote>

<h3 id="pod-template-hash-label">Pod-template-hash label</h3>

<blockquote class="note">
  <div><strong>Note:</strong> Do not change this label.</div>
</blockquote>

<p>The <code>pod-template-hash</code> label is added by the Deployment controller to every ReplicaSet that a Deployment creates or adopts.</p>

<p>This label ensures that child ReplicaSets of a Deployment do not overlap. It is generated by hashing the <code>PodTemplate</code> of the ReplicaSet and using the resulting hash as the label value that is added to the ReplicaSet selector, Pod template labels,
and in any existing Pods that the ReplicaSet might have.</p>

<h2 id="updating-a-deployment">Updating a Deployment</h2>

<blockquote class="note">
  <div><strong>Note:</strong> A Deployment&rsquo;s rollout is triggered if and only if the Deployment&rsquo;s pod template (that is, <code>.spec.template</code>)
is changed, for example if the labels or container images of the template are updated. Other updates, such as scaling the Deployment, do not trigger a rollout.</div>
</blockquote>

<p>Suppose that we now want to update the nginx Pods to use the <code>nginx:1.9.1</code> image
instead of the <code>nginx:1.7.9</code> image.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl <span style="color:#a2f">set</span> image deployment/nginx-deployment <span style="color:#b8860b">nginx</span><span style="color:#666">=</span>nginx:1.9.1
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> image updated</code></pre></div>
<p>Alternatively, we can <code>edit</code> the Deployment and change <code>.spec.template.spec.containers[0].image</code> from <code>nginx:1.7.9</code> to <code>nginx:1.9.1</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl edit deployment/nginx-deployment
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> edited</code></pre></div>
<p>To see the rollout status, run:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout status deployment/nginx-deployment
Waiting <span style="color:#a2f;font-weight:bold">for</span> rollout to finish: <span style="color:#666">2</span> out of <span style="color:#666">3</span> new replicas have been updated...
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> successfully rolled out</code></pre></div>
<p>After the rollout succeeds, you may want to <code>get</code> the Deployment:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>            <span style="color:#666">3</span>           36s</code></pre></div>
<p>The number of up-to-date replicas indicates that the Deployment has updated the replicas to the latest configuration.
The current replicas indicates the total replicas this Deployment manages, and the available replicas indicates the
number of current replicas that are available.</p>

<p>We can run <code>kubectl get rs</code> to see that the Deployment updated the Pods by creating a new ReplicaSet and scaling it
up to 3 replicas, as well as scaling down the old ReplicaSet to 0 replicas.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get rs
NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-1564180365   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>       6s
nginx-deployment-2035384211   <span style="color:#666">0</span>         <span style="color:#666">0</span>         <span style="color:#666">0</span>       36s</code></pre></div>
<p>Running <code>get pods</code> should now show only the new Pods:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get pods
NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-1564180365-khku8   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          14s
nginx-deployment-1564180365-nacti   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          14s
nginx-deployment-1564180365-z9gth   <span style="color:#666">1</span>/1       Running   <span style="color:#666">0</span>          14s</code></pre></div>
<p>Next time we want to update these Pods, we only need to update the Deployment&rsquo;s pod template again.</p>

<p>Deployment can ensure that only a certain number of Pods may be down while they are being updated. By
default, it ensures that at least 25% less than the desired number of Pods are up (25% max unavailable).</p>

<p>Deployment can also ensure that only a certain number of Pods may be created above the desired number of
Pods. By default, it ensures that at most 25% more than the desired number of Pods are up (25% max surge).</p>

<p>For example, if you look at the above Deployment closely, you will see that it first created a new Pod,
then deleted some old Pods and created new ones. It does not kill old Pods until a sufficient number of
new Pods have come up, and does not create new Pods until a sufficient number of old Pods have been killed.
It makes sure that number of available Pods is at least 2 and the number of total Pods is at most 4.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl describe deployments
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Thu, <span style="color:#666">30</span> Nov <span style="color:#666">2017</span> <span style="color:#666">10</span>:56:25 +0000
Labels:                 <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
Annotations:            deployment.kubernetes.io/revision<span style="color:#666">=</span><span style="color:#666">2</span>
Selector:               <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
Replicas:               <span style="color:#666">3</span> desired | <span style="color:#666">3</span> updated | <span style="color:#666">3</span> total | <span style="color:#666">3</span> available | <span style="color:#666">0</span> unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        <span style="color:#666">0</span>
RollingUpdateStrategy:  <span style="color:#666">25</span>% max unavailable, <span style="color:#666">25</span>% max surge
Pod Template:
  Labels:  <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
  Containers:
   nginx:
    Image:        nginx:1.9.1
    Port:         <span style="color:#666">80</span>/TCP
    Environment:  &lt;none&gt;
    Mounts:       &lt;none&gt;
  Volumes:        &lt;none&gt;
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  &lt;none&gt;
NewReplicaSet:   nginx-deployment-1564180365 <span style="color:#666">(</span><span style="color:#666">3</span>/3 replicas created<span style="color:#666">)</span>
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  2m    deployment-controller  Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">3</span>
  Normal  ScalingReplicaSet  24s   deployment-controller  Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">1</span>
  Normal  ScalingReplicaSet  22s   deployment-controller  Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">2</span>
  Normal  ScalingReplicaSet  22s   deployment-controller  Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">2</span>
  Normal  ScalingReplicaSet  19s   deployment-controller  Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">1</span>
  Normal  ScalingReplicaSet  19s   deployment-controller  Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">3</span>
  Normal  ScalingReplicaSet  14s   deployment-controller  Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">0</span></code></pre></div>
<p>Here we see that when we first created the Deployment, it created a ReplicaSet (nginx-deployment-2035384211)
and scaled it up to 3 replicas directly. When we updated the Deployment, it created a new ReplicaSet
(nginx-deployment-1564180365) and scaled it up to 1 and then scaled down the old ReplicaSet to 2, so that at
least 2 Pods were available and at most 4 Pods were created at all times. It then continued scaling up and down
the new and the old ReplicaSet, with the same rolling update strategy. Finally, we&rsquo;ll have 3 available replicas
in the new ReplicaSet, and the old ReplicaSet is scaled down to 0.</p>

<h3 id="rollover-aka-multiple-updates-in-flight">Rollover (aka multiple updates in-flight)</h3>

<p>Each time a new deployment object is observed by the Deployment controller, a ReplicaSet is created to bring up
the desired Pods if there is no existing ReplicaSet doing so. Existing ReplicaSet controlling Pods whose labels
match <code>.spec.selector</code> but whose template does not match <code>.spec.template</code> are scaled down. Eventually, the new
ReplicaSet will be scaled to <code>.spec.replicas</code> and all old ReplicaSets will be scaled to 0.</p>

<p>If you update a Deployment while an existing rollout is in progress, the Deployment will create a new ReplicaSet
as per the update and start scaling that up, and will roll over the ReplicaSet that it was scaling up previously
 &ndash; it will add it to its list of old ReplicaSets and will start scaling it down.</p>

<p>For example, suppose you create a Deployment to create 5 replicas of <code>nginx:1.7.9</code>,
but then updates the Deployment to create 5 replicas of <code>nginx:1.9.1</code>, when only 3
replicas of <code>nginx:1.7.9</code> had been created. In that case, Deployment will immediately start
killing the 3 <code>nginx:1.7.9</code> Pods that it had created, and will start creating
<code>nginx:1.9.1</code> Pods. It will not wait for 5 replicas of <code>nginx:1.7.9</code> to be created
before changing course.</p>

<h3 id="label-selector-updates">Label selector updates</h3>

<p>It is generally discouraged to make label selector updates and it is suggested to plan your selectors up front.
In any case, if you need to perform a label selector update, exercise great caution and make sure you have grasped
all of the implications.</p>

<blockquote class="note">
  <div><strong>Note:</strong> In API version <code>apps/v1</code>, a Deployment&rsquo;s label selector is immutable after it gets created.</div>
</blockquote>

<ul>
<li>Selector additions require the pod template labels in the Deployment spec to be updated with the new label too,
otherwise a validation error is returned. This change is a non-overlapping one, meaning that the new selector does
not select ReplicaSets and Pods created with the old selector, resulting in orphaning all old ReplicaSets and
creating a new ReplicaSet.</li>
<li>Selector updates &ndash; that is, changing the existing value in a selector key &ndash; result in the same behavior as additions.</li>
<li>Selector removals &ndash; that is, removing an existing key from the Deployment selector &ndash; do not require any changes in the
pod template labels. No existing ReplicaSet is orphaned, and a new ReplicaSet is not created, but note that the
removed label still exists in any existing Pods and ReplicaSets.</li>
</ul>

<h2 id="rolling-back-a-deployment">Rolling Back a Deployment</h2>

<p>Sometimes you may want to rollback a Deployment; for example, when the Deployment is not stable, such as crash looping.
By default, all of the Deployment&rsquo;s rollout history is kept in the system so that you can rollback anytime you want
(you can change that by modifying revision history limit).</p>

<blockquote class="note">
  <div><strong>Note:</strong> A Deployment&rsquo;s revision is created when a Deployment&rsquo;s rollout is triggered. This means that the
new revision is created if and only if the Deployment&rsquo;s pod template (<code>.spec.template</code>) is changed,
for example if you update the labels or container images of the template. Other updates, such as scaling the Deployment,
do not create a Deployment revision, so that we can facilitate simultaneous manual- or auto-scaling.
This means that when you roll back to an earlier revision, only the Deployment&rsquo;s pod template part is
rolled back.</div>
</blockquote>

<p>Suppose that we made a typo while updating the Deployment, by putting the image name as <code>nginx:1.91</code> instead of <code>nginx:1.9.1</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl <span style="color:#a2f">set</span> image deployment/nginx-deployment <span style="color:#b8860b">nginx</span><span style="color:#666">=</span>nginx:1.91
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> image updated</code></pre></div>
<p>The rollout will be stuck.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout status deployments nginx-deployment
Waiting <span style="color:#a2f;font-weight:bold">for</span> rollout to finish: <span style="color:#666">2</span> out of <span style="color:#666">3</span> new replicas have been updated...</code></pre></div>
<p>Press Ctrl-C to stop the above rollout status watch. For more information on stuck rollouts,
<a href="index.html#deployment-status">read more here</a>.</p>

<p>You will also see that both the number of old replicas (nginx-deployment-1564180365 and
nginx-deployment-2035384211) and new replicas (nginx-deployment-3066724191) are 2.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get rs
NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-1564180365   <span style="color:#666">2</span>         <span style="color:#666">2</span>         <span style="color:#666">0</span>       25s
nginx-deployment-2035384211   <span style="color:#666">0</span>         <span style="color:#666">0</span>         <span style="color:#666">0</span>       36s
nginx-deployment-3066724191   <span style="color:#666">2</span>         <span style="color:#666">2</span>         <span style="color:#666">2</span>       6s</code></pre></div>
<p>Looking at the Pods created, you will see that the 2 Pods created by new ReplicaSet are stuck in an image pull loop.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get pods
NAME                                READY     STATUS             RESTARTS   AGE
nginx-deployment-1564180365-70iae   <span style="color:#666">1</span>/1       Running            <span style="color:#666">0</span>          25s
nginx-deployment-1564180365-jbqqo   <span style="color:#666">1</span>/1       Running            <span style="color:#666">0</span>          25s
nginx-deployment-3066724191-08mng   <span style="color:#666">0</span>/1       ImagePullBackOff   <span style="color:#666">0</span>          6s
nginx-deployment-3066724191-eocby   <span style="color:#666">0</span>/1       ImagePullBackOff   <span style="color:#666">0</span>          6s</code></pre></div>
<blockquote class="note">
  <div><strong>Note:</strong> The Deployment controller will stop the bad rollout automatically, and will stop scaling up the new
ReplicaSet. This depends on the rollingUpdate parameters (<code>maxUnavailable</code> specifically) that you have specified.
Kubernetes by default sets the value to 1 and <code>.spec.replicas</code> to 1 so if you haven&rsquo;t cared about setting those
parameters, your Deployment can have 100% unavailability by default! This will be fixed in Kubernetes in a future
version.</div>
</blockquote>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl describe deployment
Name:           nginx-deployment
Namespace:      default
CreationTimestamp:  Tue, <span style="color:#666">15</span> Mar <span style="color:#666">2016</span> <span style="color:#666">14</span>:48:04 -0700
Labels:         <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
Selector:       <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
Replicas:       <span style="color:#666">2</span> updated | <span style="color:#666">3</span> total | <span style="color:#666">2</span> available | <span style="color:#666">2</span> unavailable
StrategyType:       RollingUpdate
MinReadySeconds:    <span style="color:#666">0</span>
RollingUpdateStrategy:  <span style="color:#666">1</span> max unavailable, <span style="color:#666">1</span> max surge
OldReplicaSets:     nginx-deployment-1564180365 <span style="color:#666">(</span><span style="color:#666">2</span>/2 replicas created<span style="color:#666">)</span>
NewReplicaSet:      nginx-deployment-3066724191 <span style="color:#666">(</span><span style="color:#666">2</span>/2 replicas created<span style="color:#666">)</span>
Events:
  FirstSeen LastSeen    Count   From                    SubobjectPath   Type        Reason              Message
  --------- --------    -----   ----                    -------------   --------    ------              -------
  1m        1m          <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">3</span>
  22s       22s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">1</span>
  22s       22s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">2</span>
  22s       22s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">2</span>
  21s       21s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">0</span>
  21s       21s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">3</span>
  13s       13s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-3066724191 to <span style="color:#666">1</span>
  13s       13s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">2</span>
  13s       13s         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-3066724191 to <span style="color:#666">2</span></code></pre></div>
<p>To fix this, we need to rollback to a previous revision of Deployment that is stable.</p>

<h3 id="checking-rollout-history-of-a-deployment">Checking Rollout History of a Deployment</h3>

<p>First, check the revisions of this deployment:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout <span style="color:#a2f">history</span> deployment/nginx-deployment
deployments <span style="color:#b44">&#34;nginx-deployment&#34;</span>
REVISION    CHANGE-CAUSE
<span style="color:#666">1</span>           kubectl create -f docs/user-guide/nginx-deployment.yaml --record
<span style="color:#666">2</span>           kubectl <span style="color:#a2f">set</span> image deployment/nginx-deployment <span style="color:#b8860b">nginx</span><span style="color:#666">=</span>nginx:1.9.1
<span style="color:#666">3</span>           kubectl <span style="color:#a2f">set</span> image deployment/nginx-deployment <span style="color:#b8860b">nginx</span><span style="color:#666">=</span>nginx:1.91</code></pre></div>
<p>Because we recorded the command while creating this Deployment using <code>--record</code>, we can easily see
the changes we made in each revision.</p>

<p>To further see the details of each revision, run:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout <span style="color:#a2f">history</span> deployment/nginx-deployment --revision<span style="color:#666">=</span><span style="color:#666">2</span>
deployments <span style="color:#b44">&#34;nginx-deployment&#34;</span> revision <span style="color:#666">2</span>
  Labels:       <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
          pod-template-hash<span style="color:#666">=</span><span style="color:#666">1159050644</span>
  Annotations:  kubernetes.io/change-cause<span style="color:#666">=</span>kubectl <span style="color:#a2f">set</span> image deployment/nginx-deployment <span style="color:#b8860b">nginx</span><span style="color:#666">=</span>nginx:1.9.1
  Containers:
   nginx:
    Image:      nginx:1.9.1
    Port:       <span style="color:#666">80</span>/TCP
     QoS Tier:
        cpu:      BestEffort
        memory:   BestEffort
    Environment Variables:      &lt;none&gt;
  No volumes.</code></pre></div>
<h3 id="rolling-back-to-a-previous-revision">Rolling Back to a Previous Revision</h3>

<p>Now we&rsquo;ve decided to undo the current rollout and rollback to the previous revision:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout undo deployment/nginx-deployment
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> rolled back</code></pre></div>
<p>Alternatively, you can rollback to a specific revision by specify that in <code>--to-revision</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout undo deployment/nginx-deployment --to-revision<span style="color:#666">=</span><span style="color:#666">2</span>
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> rolled back</code></pre></div>
<p>For more details about rollout related commands, read <a href="../../../../reference/generated/kubectl/kubectl/index.html#rollout"><code>kubectl rollout</code></a>.</p>

<p>The Deployment is now rolled back to a previous stable revision. As you can see, a <code>DeploymentRollback</code> event
for rolling back to revision 2 is generated from Deployment controller.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get deployment
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>            <span style="color:#666">3</span>           30m

$ kubectl describe deployment
Name:           nginx-deployment
Namespace:      default
CreationTimestamp:  Tue, <span style="color:#666">15</span> Mar <span style="color:#666">2016</span> <span style="color:#666">14</span>:48:04 -0700
Labels:         <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
Selector:       <span style="color:#b8860b">app</span><span style="color:#666">=</span>nginx
Replicas:       <span style="color:#666">3</span> updated | <span style="color:#666">3</span> total | <span style="color:#666">3</span> available | <span style="color:#666">0</span> unavailable
StrategyType:       RollingUpdate
MinReadySeconds:    <span style="color:#666">0</span>
RollingUpdateStrategy:  <span style="color:#666">1</span> max unavailable, <span style="color:#666">1</span> max surge
OldReplicaSets:     &lt;none&gt;
NewReplicaSet:      nginx-deployment-1564180365 <span style="color:#666">(</span><span style="color:#666">3</span>/3 replicas created<span style="color:#666">)</span>
Events:
  FirstSeen LastSeen    Count   From                    SubobjectPath   Type        Reason              Message
  --------- --------    -----   ----                    -------------   --------    ------              -------
  30m       30m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">3</span>
  29m       29m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">1</span>
  29m       29m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">2</span>
  29m       29m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">2</span>
  29m       29m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-2035384211 to <span style="color:#666">0</span>
  29m       29m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-3066724191 to <span style="color:#666">2</span>
  29m       29m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-3066724191 to <span style="color:#666">1</span>
  29m       29m         <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">2</span>
  2m        2m          <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled down replica <span style="color:#a2f">set</span> nginx-deployment-3066724191 to <span style="color:#666">0</span>
  2m        2m          <span style="color:#666">1</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      DeploymentRollback  Rolled back deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> to revision <span style="color:#666">2</span>
  29m       2m          <span style="color:#666">2</span>       <span style="color:#666">{</span>deployment-controller <span style="color:#666">}</span>                Normal      ScalingReplicaSet   Scaled up replica <span style="color:#a2f">set</span> nginx-deployment-1564180365 to <span style="color:#666">3</span></code></pre></div>
<h2 id="scaling-a-deployment">Scaling a Deployment</h2>

<p>You can scale a Deployment by using the following command:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl scale deployment nginx-deployment --replicas<span style="color:#666">=</span><span style="color:#666">10</span>
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> scaled</code></pre></div>
<p>Assuming <a href="../../../../tasks/run-application/horizontal-pod-autoscale-walkthrough/index.html">horizontal pod autoscaling</a> is enabled
in your cluster, you can setup an autoscaler for your Deployment and choose the minimum and maximum number of
Pods you want to run based on the CPU utilization of your existing Pods.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl autoscale deployment nginx-deployment --min<span style="color:#666">=</span><span style="color:#666">10</span> --max<span style="color:#666">=</span><span style="color:#666">15</span> --cpu-percent<span style="color:#666">=</span><span style="color:#666">80</span>
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> autoscaled</code></pre></div>
<h3 id="proportional-scaling">Proportional scaling</h3>

<p>RollingUpdate Deployments support running multiple versions of an application at the same time. When you
or an autoscaler scales a RollingUpdate Deployment that is in the middle of a rollout (either in progress
or paused), then the Deployment controller will balance the additional replicas in the existing active
ReplicaSets (ReplicaSets with Pods) in order to mitigate risk. This is called <em>proportional scaling</em>.</p>

<p>For example, you are running a Deployment with 10 replicas, <a href="index.html#max-surge">maxSurge</a>=3, and <a href="index.html#max-unavailable">maxUnavailable</a>=2.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get deploy
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment     <span style="color:#666">10</span>        <span style="color:#666">10</span>        <span style="color:#666">10</span>           <span style="color:#666">10</span>          50s</code></pre></div>
<p>You update to a new image which happens to be unresolvable from inside the cluster.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl <span style="color:#a2f">set</span> image deploy/nginx-deployment <span style="color:#b8860b">nginx</span><span style="color:#666">=</span>nginx:sometag
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> image updated</code></pre></div>
<p>The image update starts a new rollout with ReplicaSet nginx-deployment-1989198191, but it&rsquo;s blocked due to the
<code>maxUnavailable</code> requirement that we mentioned above.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get rs
NAME                          DESIRED   CURRENT   READY     AGE
nginx-deployment-1989198191   <span style="color:#666">5</span>         <span style="color:#666">5</span>         <span style="color:#666">0</span>         9s
nginx-deployment-618515232    <span style="color:#666">8</span>         <span style="color:#666">8</span>         <span style="color:#666">8</span>         1m</code></pre></div>
<p>Then a new scaling request for the Deployment comes along. The autoscaler increments the Deployment replicas
to 15. The Deployment controller needs to decide where to add these new 5 replicas. If we weren&rsquo;t using
proportional scaling, all 5 of them would be added in the new ReplicaSet. With proportional scaling, we
spread the additional replicas across all ReplicaSets. Bigger proportions go to the ReplicaSets with the
most replicas and lower proportions go to ReplicaSets with less replicas. Any leftovers are added to the
ReplicaSet with the most replicas. ReplicaSets with zero replicas are not scaled up.</p>

<p>In our example above, 3 replicas will be added to the old ReplicaSet and 2 replicas will be added to the
new ReplicaSet. The rollout process should eventually move all replicas to the new ReplicaSet, assuming
the new replicas become healthy.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get deploy
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment     <span style="color:#666">15</span>        <span style="color:#666">18</span>        <span style="color:#666">7</span>            <span style="color:#666">8</span>           7m
$ kubectl get rs
NAME                          DESIRED   CURRENT   READY     AGE
nginx-deployment-1989198191   <span style="color:#666">7</span>         <span style="color:#666">7</span>         <span style="color:#666">0</span>         7m
nginx-deployment-618515232    <span style="color:#666">11</span>        <span style="color:#666">11</span>        <span style="color:#666">11</span>        7m</code></pre></div>
<h2 id="pausing-and-resuming-a-deployment">Pausing and Resuming a Deployment</h2>

<p>You can pause a Deployment before triggering one or more updates and then resume it. This will allow you to
apply multiple fixes in between pausing and resuming without triggering unnecessary rollouts.</p>

<p>For example, with a Deployment that was just created:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get deploy
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>            <span style="color:#666">3</span>           1m
$ kubectl get rs
NAME               DESIRED   CURRENT   READY     AGE
nginx-2142116321   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>         1m</code></pre></div>
<p>Pause by running the following command:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout pause deployment/nginx-deployment
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> paused</code></pre></div>
<p>Then update the image of the Deployment:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl <span style="color:#a2f">set</span> image deploy/nginx-deployment <span style="color:#b8860b">nginx</span><span style="color:#666">=</span>nginx:1.9.1
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> image updated</code></pre></div>
<p>Notice that no new rollout started:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout <span style="color:#a2f">history</span> deploy/nginx-deployment
deployments <span style="color:#b44">&#34;nginx&#34;</span>
REVISION  CHANGE-CAUSE
<span style="color:#666">1</span>   &lt;none&gt;

$ kubectl get rs
NAME               DESIRED   CURRENT   READY     AGE
nginx-2142116321   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>         2m</code></pre></div>
<p>You can make as many updates as you wish, for example, update the resources that will be used:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl <span style="color:#a2f">set</span> resources deployment nginx-deployment -c<span style="color:#666">=</span>nginx --limits<span style="color:#666">=</span><span style="color:#b8860b">cpu</span><span style="color:#666">=</span>200m,memory<span style="color:#666">=</span>512Mi
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> resource requirements updated</code></pre></div>
<p>The initial state of the Deployment prior to pausing it will continue its function, but new updates to
the Deployment will not have any effect as long as the Deployment is paused.</p>

<p>Eventually, resume the Deployment and observe a new ReplicaSet coming up with all the new updates:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout resume deploy/nginx-deployment
deployment <span style="color:#b44">&#34;nginx&#34;</span> resumed
$ kubectl get rs -w
NAME               DESIRED   CURRENT   READY     AGE
nginx-2142116321   <span style="color:#666">2</span>         <span style="color:#666">2</span>         <span style="color:#666">2</span>         2m
nginx-3926361531   <span style="color:#666">2</span>         <span style="color:#666">2</span>         <span style="color:#666">0</span>         6s
nginx-3926361531   <span style="color:#666">2</span>         <span style="color:#666">2</span>         <span style="color:#666">1</span>         18s
nginx-2142116321   <span style="color:#666">1</span>         <span style="color:#666">2</span>         <span style="color:#666">2</span>         2m
nginx-2142116321   <span style="color:#666">1</span>         <span style="color:#666">2</span>         <span style="color:#666">2</span>         2m
nginx-3926361531   <span style="color:#666">3</span>         <span style="color:#666">2</span>         <span style="color:#666">1</span>         18s
nginx-3926361531   <span style="color:#666">3</span>         <span style="color:#666">2</span>         <span style="color:#666">1</span>         18s
nginx-2142116321   <span style="color:#666">1</span>         <span style="color:#666">1</span>         <span style="color:#666">1</span>         2m
nginx-3926361531   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">1</span>         18s
nginx-3926361531   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">2</span>         19s
nginx-2142116321   <span style="color:#666">0</span>         <span style="color:#666">1</span>         <span style="color:#666">1</span>         2m
nginx-2142116321   <span style="color:#666">0</span>         <span style="color:#666">1</span>         <span style="color:#666">1</span>         2m
nginx-2142116321   <span style="color:#666">0</span>         <span style="color:#666">0</span>         <span style="color:#666">0</span>         2m
nginx-3926361531   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>         20s
^C
$ kubectl get rs
NAME               DESIRED   CURRENT   READY     AGE
nginx-2142116321   <span style="color:#666">0</span>         <span style="color:#666">0</span>         <span style="color:#666">0</span>         2m
nginx-3926361531   <span style="color:#666">3</span>         <span style="color:#666">3</span>         <span style="color:#666">3</span>         28s</code></pre></div>
<blockquote class="note">
  <div><strong>Note:</strong> You cannot rollback a paused Deployment until you resume it.</div>
</blockquote>

<h2 id="deployment-status">Deployment status</h2>

<p>A Deployment enters various states during its lifecycle. It can be <a href="index.html#progressing-deployment">progressing</a> while
rolling out a new ReplicaSet, it can be <a href="index.html#complete-deployment">complete</a>, or it can <a href="index.html#failed-deployment">fail to progress</a>.</p>

<h3 id="progressing-deployment">Progressing Deployment</h3>

<p>Kubernetes marks a Deployment as <em>progressing</em> when one of the following tasks is performed:</p>

<ul>
<li>The Deployment creates a new ReplicaSet.</li>
<li>The Deployment is scaling up its newest ReplicaSet.</li>
<li>The Deployment is scaling down its older ReplicaSet(s).</li>
<li>New Pods become ready or available (ready for at least <a href="index.html#min-ready-seconds">MinReadySeconds</a>).</li>
</ul>

<p>You can monitor the progress for a Deployment by using <code>kubectl rollout status</code>.</p>

<h3 id="complete-deployment">Complete Deployment</h3>

<p>Kubernetes marks a Deployment as <em>complete</em> when it has the following characteristics:</p>

<ul>
<li>All of the replicas associated with the Deployment have been updated to the latest version you&rsquo;ve specified, meaning any
updates you&rsquo;ve requested have been completed.</li>
<li>All of the replicas associated with the Deployment are available.</li>
<li>No old replicas for the Deployment are running.</li>
</ul>

<p>You can check if a Deployment has completed by using <code>kubectl rollout status</code>. If the rollout completed
successfully, <code>kubectl rollout status</code> returns a zero exit code.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout status deploy/nginx-deployment
Waiting <span style="color:#a2f;font-weight:bold">for</span> rollout to finish: <span style="color:#666">2</span> of <span style="color:#666">3</span> updated replicas are available...
deployment <span style="color:#b44">&#34;nginx&#34;</span> successfully rolled out
$ <span style="color:#a2f">echo</span> <span style="color:#b8860b">$?</span>
<span style="color:#666">0</span></code></pre></div>
<h3 id="failed-deployment">Failed Deployment</h3>

<p>Your Deployment may get stuck trying to deploy its newest ReplicaSet without ever completing. This can occur
due to some of the following factors:</p>

<ul>
<li>Insufficient quota</li>
<li>Readiness probe failures</li>
<li>Image pull errors</li>
<li>Insufficient permissions</li>
<li>Limit ranges</li>
<li>Application runtime misconfiguration</li>
</ul>

<p>One way you can detect this condition is to specify a deadline parameter in your Deployment spec:
(<a href="index.html#progress-deadline-seconds"><code>.spec.progressDeadlineSeconds</code></a>). <code>.spec.progressDeadlineSeconds</code> denotes the
number of seconds the Deployment controller waits before indicating (in the Deployment status) that the
Deployment progress has stalled.</p>

<p>The following <code>kubectl</code> command sets the spec with <code>progressDeadlineSeconds</code> to make the controller report
lack of progress for a Deployment after 10 minutes:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl patch deployment/nginx-deployment -p <span style="color:#b44">&#39;{&#34;spec&#34;:{&#34;progressDeadlineSeconds&#34;:600}}&#39;</span>
deployment <span style="color:#b44">&#34;nginx-deployment&#34;</span> patched</code></pre></div>
<p>Once the deadline has been exceeded, the Deployment controller adds a DeploymentCondition with the following
attributes to the Deployment&rsquo;s <code>.status.conditions</code>:</p>

<ul>
<li>Type=Progressing</li>
<li>Status=False</li>
<li>Reason=ProgressDeadlineExceeded</li>
</ul>

<p>See the <a href="https://git.k8s.io/community/contributors/devel/api-conventions.md#typical-status-properties" target="_blank">Kubernetes API conventions</a> for more information on status conditions.</p>

<blockquote class="note">
  <div><strong>Note:</strong> Kubernetes will take no action on a stalled Deployment other than to report a status condition with
<code>Reason=ProgressDeadlineExceeded</code>. Higher level orchestrators can take advantage of it and act accordingly, for
example, rollback the Deployment to its previous version.</div>
</blockquote>

<blockquote class="note">
  <div><strong>Note:</strong> If you pause a Deployment, Kubernetes does not check progress against your specified deadline. You can
safely pause a Deployment in the middle of a rollout and resume without triggering the condition for exceeding the
deadline.</div>
</blockquote>

<p>You may experience transient errors with your Deployments, either due to a low timeout that you have set or
due to any other kind of error that can be treated as transient. For example, let&rsquo;s suppose you have
insufficient quota. If you describe the Deployment you will notice the following section:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl describe deployment nginx-deployment
&lt;...&gt;
Conditions:
  Type            Status  Reason
  ----            ------  ------
  Available       True    MinimumReplicasAvailable
  Progressing     True    ReplicaSetUpdated
  ReplicaFailure  True    FailedCreate
&lt;...&gt;</code></pre></div>
<p>If you run <code>kubectl get deployment nginx-deployment -o yaml</code>, the Deployment status might look like this:</p>

<pre><code>status:
  availableReplicas: 2
  conditions:
  - lastTransitionTime: 2016-10-04T12:25:39Z
    lastUpdateTime: 2016-10-04T12:25:39Z
    message: Replica set &quot;nginx-deployment-4262182780&quot; is progressing.
    reason: ReplicaSetUpdated
    status: &quot;True&quot;
    type: Progressing
  - lastTransitionTime: 2016-10-04T12:25:42Z
    lastUpdateTime: 2016-10-04T12:25:42Z
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: &quot;True&quot;
    type: Available
  - lastTransitionTime: 2016-10-04T12:25:39Z
    lastUpdateTime: 2016-10-04T12:25:39Z
    message: 'Error creating: pods &quot;nginx-deployment-4262182780-&quot; is forbidden: exceeded quota:
      object-counts, requested: pods=1, used: pods=3, limited: pods=2'
    reason: FailedCreate
    status: &quot;True&quot;
    type: ReplicaFailure
  observedGeneration: 3
  replicas: 2
  unavailableReplicas: 2
</code></pre>

<p>Eventually, once the Deployment progress deadline is exceeded, Kubernetes updates the status and the
reason for the Progressing condition:</p>

<pre><code>Conditions:
  Type            Status  Reason
  ----            ------  ------
  Available       True    MinimumReplicasAvailable
  Progressing     False   ProgressDeadlineExceeded
  ReplicaFailure  True    FailedCreate
</code></pre>

<p>You can address an issue of insufficient quota by scaling down your Deployment, by scaling down other
controllers you may be running, or by increasing quota in your namespace. If you satisfy the quota
conditions and the Deployment controller then completes the Deployment rollout, you&rsquo;ll see the
Deployment&rsquo;s status update with a successful condition (<code>Status=True</code> and <code>Reason=NewReplicaSetAvailable</code>).</p>

<pre><code>Conditions:
  Type          Status  Reason
  ----          ------  ------
  Available     True    MinimumReplicasAvailable
  Progressing   True    NewReplicaSetAvailable
</code></pre>

<p><code>Type=Available</code> with <code>Status=True</code> means that your Deployment has minimum availability. Minimum availability is dictated
by the parameters specified in the deployment strategy. <code>Type=Progressing</code> with <code>Status=True</code> means that your Deployment
is either in the middle of a rollout and it is progressing or that it has successfully completed its progress and the minimum
required new replicas are available (see the Reason of the condition for the particulars - in our case
<code>Reason=NewReplicaSetAvailable</code> means that the Deployment is complete).</p>

<p>You can check if a Deployment has failed to progress by using <code>kubectl rollout status</code>. <code>kubectl rollout status</code>
returns a non-zero exit code if the Deployment has exceeded the progression deadline.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl rollout status deploy/nginx-deployment
Waiting <span style="color:#a2f;font-weight:bold">for</span> rollout to finish: <span style="color:#666">2</span> out of <span style="color:#666">3</span> new replicas have been updated...
error: deployment <span style="color:#b44">&#34;nginx&#34;</span> exceeded its progress deadline
$ <span style="color:#a2f">echo</span> <span style="color:#b8860b">$?</span>
<span style="color:#666">1</span></code></pre></div>
<h3 id="operating-on-a-failed-deployment">Operating on a failed deployment</h3>

<p>All actions that apply to a complete Deployment also apply to a failed Deployment. You can scale it up/down, roll back
to a previous revision, or even pause it if you need to apply multiple tweaks in the Deployment pod template.</p>

<h2 id="clean-up-policy">Clean up Policy</h2>

<p>You can set <code>.spec.revisionHistoryLimit</code> field in a Deployment to specify how many old ReplicaSets for
this Deployment you want to retain. The rest will be garbage-collected in the background. By default,
it is 10.</p>

<blockquote class="note">
  <div><strong>Note:</strong> Explicitly setting this field to 0, will result in cleaning up all the history of your Deployment
thus that Deployment will not be able to roll back.</div>
</blockquote>

<h2 id="use-cases">Use Cases</h2>

<h3 id="canary-deployment">Canary Deployment</h3>

<p>If you want to roll out releases to a subset of users or servers using the Deployment, you
can create multiple Deployments, one for each release, following the canary pattern described in
<a href="../../../cluster-administration/manage-deployment/index.html#canary-deployments">managing resources</a>.</p>

<h2 id="writing-a-deployment-spec">Writing a Deployment Spec</h2>

<p>As with all other Kubernetes configs, a Deployment needs <code>apiVersion</code>, <code>kind</code>, and <code>metadata</code> fields.
For general information about working with config files, see <a href="../../../../tutorials/stateless-application/run-stateless-application-deployment/index.html">deploying applications</a>,
configuring containers, and <a href="../../../../tutorials/object-management-kubectl/object-management/index.html">using kubectl to manage resources</a> documents.</p>

<p>A Deployment also needs a <a href="https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status" target="_blank"><code>.spec</code> section</a>.</p>

<h3 id="pod-template">Pod Template</h3>

<p>The <code>.spec.template</code> is the only required field of the <code>.spec</code>.</p>

<p>The <code>.spec.template</code> is a <a href="../../pods/pod-overview/index.html#pod-templates">pod template</a>. It has exactly the same schema as a <a href="../../../../user-guide/pods/index.html">Pod</a>, except it is nested and does not have an
<code>apiVersion</code> or <code>kind</code>.</p>

<p>In addition to required fields for a Pod, a pod template in a Deployment must specify appropriate
labels and an appropriate restart policy. For labels, make sure not to overlap with other controllers. See <a href="index.html#selector">selector</a>).</p>

<p>Only a <a href="../../../../user-guide/pod-states/index.html#restart-policy"><code>.spec.template.spec.restartPolicy</code></a> equal to <code>Always</code> is
allowed, which is the default if not specified.</p>

<h3 id="replicas">Replicas</h3>

<p><code>.spec.replicas</code> is an optional field that specifies the number of desired Pods. It defaults to 1.</p>

<h3 id="selector">Selector</h3>

<p><code>.spec.selector</code> is an optional field that specifies a <a href="../../../../user-guide/labels">label selector</a>
for the Pods targeted by this deployment.</p>

<p><code>.spec.selector</code> must match <code>.spec.template.metadata.labels</code>, or it will be rejected by the API.</p>

<p>In API version <code>apps/v1</code>, <code>.spec.selector</code> and <code>.metadata.labels</code> do not default to <code>.spec.template.metadata.labels</code> if not set. So they must be set explicitly. Also note that <code>.spec.selector</code> is immutable after creation of the Deployment in <code>apps/v1</code>.</p>

<p>A Deployment may terminate Pods whose labels match the selector if their template is different
from <code>.spec.template</code> or if the total number of such Pods exceeds <code>.spec.replicas</code>. It brings up new
Pods with <code>.spec.template</code> if the number of Pods is less than the desired number.</p>

<blockquote class="note">
  <div><strong>Note:</strong> You should not create other pods whose labels match this selector, either directly, by creating
another Deployment, or by creating another controller such as a ReplicaSet or a ReplicationController. If you
do so, the first Deployment thinks that it created these other pods. Kubernetes does not stop you from doing this.</div>
</blockquote>

<p>If you have multiple controllers that have overlapping selectors, the controllers will fight with each
other and won&rsquo;t behave correctly.</p>

<h3 id="strategy">Strategy</h3>

<p><code>.spec.strategy</code> specifies the strategy used to replace old Pods by new ones.
<code>.spec.strategy.type</code> can be &ldquo;Recreate&rdquo; or &ldquo;RollingUpdate&rdquo;. &ldquo;RollingUpdate&rdquo; is
the default value.</p>

<h4 id="recreate-deployment">Recreate Deployment</h4>

<p>All existing Pods are killed before new ones are created when <code>.spec.strategy.type==Recreate</code>.</p>

<h4 id="rolling-update-deployment">Rolling Update Deployment</h4>

<p>The Deployment updates Pods in a <a href="../../../../tasks/run-application/rolling-update-replication-controller/index.html">rolling update</a>
fashion when <code>.spec.strategy.type==RollingUpdate</code>. You can specify <code>maxUnavailable</code> and <code>maxSurge</code> to control
the rolling update process.</p>

<h5 id="max-unavailable">Max Unavailable</h5>

<p><code>.spec.strategy.rollingUpdate.maxUnavailable</code> is an optional field that specifies the maximum number
of Pods that can be unavailable during the update process. The value can be an absolute number (for example, 5)
or a percentage of desired Pods (for example, 10%). The absolute number is calculated from percentage by
rounding down. The value cannot be 0 if <code>.spec.strategy.rollingUpdate.maxSurge</code> is 0. The default value is 25%.</p>

<p>For example, when this value is set to 30%, the old ReplicaSet can be scaled down to 70% of desired
Pods immediately when the rolling update starts. Once new Pods are ready, old ReplicaSet can be scaled
down further, followed by scaling up the new ReplicaSet, ensuring that the total number of Pods available
at all times during the update is at least 70% of the desired Pods.</p>

<h5 id="max-surge">Max Surge</h5>

<p><code>.spec.strategy.rollingUpdate.maxSurge</code> is an optional field that specifies the maximum number of Pods
that can be created over the desired number of Pods. The value can be an absolute number (for example, 5) or a
percentage of desired Pods (for example, 10%). The value cannot be 0 if <code>MaxUnavailable</code> is 0. The absolute number
is calculated from the percentage by rounding up. The default value is 25%.</p>

<p>For example, when this value is set to 30%, the new ReplicaSet can be scaled up immediately when the
rolling update starts, such that the total number of old and new Pods does not exceed 130% of desired
Pods. Once old Pods have been killed, the new ReplicaSet can be scaled up further, ensuring that the
total number of Pods running at any time during the update is at most 130% of desired Pods.</p>

<h3 id="progress-deadline-seconds">Progress Deadline Seconds</h3>

<p><code>.spec.progressDeadlineSeconds</code> is an optional field that specifies the number of seconds you want
to wait for your Deployment to progress before the system reports back that the Deployment has
<a href="index.html#failed-deployment">failed progressing</a> - surfaced as a condition with <code>Type=Progressing</code>, <code>Status=False</code>.
and <code>Reason=ProgressDeadlineExceeded</code> in the status of the resource. The deployment controller will keep
retrying the Deployment. In the future, once automatic rollback will be implemented, the deployment
controller will roll back a Deployment as soon as it observes such a condition.</p>

<p>If specified, this field needs to be greater than <code>.spec.minReadySeconds</code>.</p>

<h3 id="min-ready-seconds">Min Ready Seconds</h3>

<p><code>.spec.minReadySeconds</code> is an optional field that specifies the minimum number of seconds for which a newly
created Pod should be ready without any of its containers crashing, for it to be considered available.
This defaults to 0 (the Pod will be considered available as soon as it is ready). To learn more about when
a Pod is considered ready, see <a href="../../../../user-guide/pod-states/index.html#container-probes">Container Probes</a>.</p>

<h3 id="rollback-to">Rollback To</h3>

<p>Field <code>.spec.rollbackTo</code> has been deprecated in API versions <code>extensions/v1beta1</code> and <code>apps/v1beta1</code>, and is no longer supported in API versions starting <code>apps/v1beta2</code>. Instead, <code>kubectl rollout undo</code> as introduced in <a href="index.html#rolling-back-to-a-previous-revision">Rolling Back to a Previous Revision</a> should be used.</p>

<h3 id="revision-history-limit">Revision History Limit</h3>

<p>A Deployment&rsquo;s revision history is stored in the replica sets it controls.</p>

<p><code>.spec.revisionHistoryLimit</code> is an optional field that specifies the number of old ReplicaSets to retain
to allow rollback. Its ideal value depends on the frequency and stability of new Deployments. All old
ReplicaSets will be kept by default, consuming resources in <code>etcd</code> and crowding the output of <code>kubectl get rs</code>,
if this field is not set. The configuration of each Deployment revision is stored in its ReplicaSets;
therefore, once an old ReplicaSet is deleted, you lose the ability to rollback to that revision of Deployment.</p>

<p>More specifically, setting this field to zero means that all old ReplicaSets with 0 replica will be cleaned up.
In this case, a new Deployment rollout cannot be undone, since its revision history is cleaned up.</p>

<h3 id="paused">Paused</h3>

<p><code>.spec.paused</code> is an optional boolean field for pausing and resuming a Deployment. The only difference between
a paused Deployment and one that is not paused, is that any changes into the PodTemplateSpec of the paused
Deployment will not trigger new rollouts as long as it is paused. A Deployment is not paused by default when
it is created.</p>

<h2 id="alternative-to-deployments">Alternative to Deployments</h2>

<h3 id="kubectl-rolling-update">kubectl rolling update</h3>

<p><a href="../../../../reference/generated/kubectl/kubectl/index.html#rolling-update"><code>kubectl rolling update</code></a> updates Pods and ReplicationControllers
in a similar fashion. But Deployments are recommended, since they are declarative, server side, and have
additional features, such as rolling back to any previous revision even after the rolling update is done.</p>














				<div class="issue-button-container">
					<p><a href="index.html"><img src="https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/concepts/workloads/controllers/deployment.md?pixel" alt="Analytics" /></a></p>
					
					
					<script type="text/javascript">
					PDRTJS_settings_8345992 = {
					"id" : "8345992",
					"unique_id" : "\/docs\/concepts\/workloads\/controllers\/deployment\/",
					"title" : "Deployments",
					"permalink" : "https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/deployment\/"
					};
					(function(d,c,j){if(!document.getElementById(j)){var pd=d.createElement(c),s;pd.id=j;pd.src=('https:'==document.location.protocol)?'https://polldaddy.com/js/rating/rating.js':'http://i0.poll.fm/js/rating/rating.js';s=document.getElementsByTagName(c)[0];s.parentNode.insertBefore(pd,s);}}(document,'script','pd-rating-js'));
					</script>
					<a href="index.html" onclick="window.open('https://github.com/kubernetes/website/issues/new?title=Issue%20with%20' +
					'k8s.io'+window.location.pathname)" class="button issue">Create an Issue</a>
					
					
					
					<a href="../../../../editdocs#docs/concepts/workloads/controllers/deployment.md" class="button issue">Edit this Page</a>
					
				</div>
			</div>
		</section>
		<footer>
    <main class="light-text">
        <nav>
            
            
            
            <a href="../../../../home.1">Documentation</a>
            
            <a href="../../../../../blog/index.html">Blog</a>
            
            <a href="../../../../../partners/index.html">Partners</a>
            
            <a href="../../../../../community/index.html">Community</a>
            
            <a href="../../../../../case-studies/index.html">Case Studies</a>
            
        </nav>
        <div class="social">
            <div>
                <a href="https://twitter.com/kubernetesio" class="twitter"><span>twitter</span></a>
                <a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
                <a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
            </div>
            <div>
                <a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>Stack Overflow</span></a>
                <a href="https://discuss.kubernetes.io" class="mailing-list"><span>Forum</span></a>
                <a href="https://calendar.google.com/calendar/embed?src=nt2tcnbtbied3l6gi2h29slvc0%40group.calendar.google.com" class="calendar"><span>Events Calendar</span></a>
            </div>
            <div>
                <a href="../../../../getting-started-guides/index.html" class="button">Get Kubernetes</a>
                <a href="https://git.k8s.io/community/contributors/guide" class="button">Contribute</a>
            </div>
        </div>
        <div id="miceType" class="center">
            &copy; 2018 The Kubernetes Authors | Documentation Distributed under <a href="https://git.k8s.io/website/LICENSE" class="light-text">CC BY 4.0</a>
        </div>
        <div id="miceType" class="center">
            Copyright &copy; 2018 The Linux Foundation&reg;. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our <a href="https://www.linuxfoundation.org/trademark-usage" class="light-text">Trademark Usage page</a>
        </div>
    </main>
</footer>

		<button class="flyout-button" onclick="kub.toggleToc()"></button>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-36037335-10', 'auto');
ga('send', 'pageview');


(function () {
    window.addEventListener('DOMContentLoaded', init)

        
        function init() {
            window.removeEventListener('DOMContentLoaded', init)
                hideNav()
        }

    function hideNav(toc){
        if (!toc) toc = document.querySelector('#docsToc')
        if (!toc) return
            var container = toc.querySelector('.container')

                
                if (container) {
                    if (container.childElementCount === 0 || toc.querySelectorAll('a.item').length === 1) {
                        toc.style.display = 'none'
                            document.getElementById('docsContent').style.width = '100%'
                    }
                } else {
                    requestAnimationFrame(function () {
                        hideNav(toc)
                    })
                }
    }
})();
</script>



	</body>
</html>